<?php

namespace app\admin\model;

use think\Model;
use traits\model\SoftDelete;

class Otc extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'user_order';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'order_type_text',
        'order_status_text',
        'coin_type_text',
        'buy_type_text',
        'checktime_text',
        'paytime_text',
        'revoketime_text'
    ];
    

    
    public function getOrderTypeList()
    {
        return ['1' => __('Order_type 1'), '2' => __('Order_type 2'), '3' => __('Order_type 3')];
    }

    public function getOrderStatusList()
    {
        return ['0' => __('Order_status 0'), '1' => __('Order_status 1'), '2' => __('Order_status 2')];
    }

    public function getCoinTypeList()
    {
        return ['1' => __('Coin_type 1'), '2' => __('Coin_type 2')];
    }

    public function getBuyTypeList()
    {
        return ['1' => __('Buy_type 1'), '2' => __('Buy_type 2')];
    }


    public function getOrderTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['order_type']) ? $data['order_type'] : '');
        $list = $this->getOrderTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getOrderStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['order_status']) ? $data['order_status'] : '');
        $list = $this->getOrderStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getCoinTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['coin_type']) ? $data['coin_type'] : '');
        $list = $this->getCoinTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getBuyTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['buy_type']) ? $data['buy_type'] : '');
        $list = $this->getBuyTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getChecktimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['checktime']) ? $data['checktime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getPaytimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['paytime']) ? $data['paytime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getRevoketimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['revoketime']) ? $data['revoketime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setChecktimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setPaytimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setRevoketimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


}
